package org.jeecg.modules.hotel.belongToSkd.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.basic.entry.service.ILwgyInoutRecordService;
import org.jeecg.modules.basic.entry.service.impl.LwgyInoutRecordServiceImpl;
import org.jeecg.modules.basic.entry.util.SenseTimeToDevice;
import org.jeecg.modules.hotel.belongToSkd.entity.HKReceiveData;
import org.jeecg.modules.hotel.belongToSkd.entity.RoomInfo;
import org.jeecg.modules.hotel.belongToSkd.mapper.LwgyHotelEventRcvMapper;
import org.jeecg.modules.hotel.belongToSkd.service.ILwgyHotelEventRcvService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * @author 11025
 */
@Service
public class LwgyHotelEventRcvServiceImpl extends ServiceImpl<LwgyHotelEventRcvMapper, HKReceiveData> implements ILwgyHotelEventRcvService {

    @Autowired
    private ILwgyInoutRecordService lwgyInoutRecordService;
    @Autowired
    private LwgyInoutRecordServiceImpl lwgyInoutRecordServiceImpl;
    @Autowired
    private LwgyHotelEventRcvMapper lwgyHotelEventRcvMapper;
    @Override
    public void writeInApartment(HKReceiveData hKReceiveData) throws ParseException {

        String entryType = hKReceiveData.getEntryType();
        int inDormNum = hKReceiveData.getInDormNum();

        String dormCode = hKReceiveData.getDormCode();
        String code = dormCode.substring(dormCode.lastIndexOf("/", dormCode.lastIndexOf("/")) + 1);
        String buildName = code.substring(0, code.indexOf("-"));
        String roomName = code.substring(buildName.length() + 1);
        boolean testData1 = "GA8".equals(buildName) && ("115".equals(roomName) || "117".equals(roomName));
        boolean testData2 = "GA1".equals(buildName) && ("101".equals(roomName) || "102".equals(roomName));

        List<RoomInfo> roomInfo = lwgyHotelEventRcvMapper.selectRoomInfo(buildName,roomName);
        if (!roomInfo.isEmpty()) {
            for (RoomInfo room : roomInfo) {
                String xq = room.getNAME();
                String lh = room.getBUILDINGNAME();
                lh = lh.substring(0, lh.indexOf("号楼"));
                if (lh.startsWith("0")) {
                    lh = lh.substring(1);
                }
                int fjh = room.getFjhao();
                if ("in".equals(entryType) && inDormNum == 1) {// 进宿舍并且在寝人数为1
                    if(testData1 || testData2) {
                        lwgyInoutRecordServiceImpl.setApartmentTemp(xq, lh, String.valueOf(fjh), "1", "0");
                    } else {
                        lwgyInoutRecordServiceImpl.setApartmentTemp(xq, lh, String.valueOf(fjh), "1", "1");
                    }
                } else if ("out".equals(entryType) && inDormNum == 0) {// 出宿舍并且在寝人数为0
                    if(testData1 || testData2) {
                        lwgyInoutRecordServiceImpl.setApartmentTemp(xq, lh, String.valueOf(fjh), "0", "0");
                    } else {
                        lwgyInoutRecordServiceImpl.setApartmentTemp(xq, lh, String.valueOf(fjh), "0", "1");
                    }
                }
            }
        }
    }

    public static void main(String[] args) {
        String dormCode = "17号楼";
        String code = dormCode.substring(0, dormCode.length() - 2);
        System.out.println("code ====== " + code);

    }
}
